package com.feng;

import org.springframework.beans.factory.BeanNameAware;
import org.springframework.context.ResourceLoaderAware;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.stereotype.Service;

import java.io.IOException;

/**
 * @description:
 * @author: lrf
 * @create: 2019-09-04
 **/
@Service
public class AwreaService implements BeanNameAware, ResourceLoaderAware {

    private ResourceLoader resourceLoader;
    private String beanName;

    @Override
    public void setResourceLoader(ResourceLoader resourceLoader) {
        this.resourceLoader = resourceLoader;
    }

    @Override
    public void setBeanName(String name) {
        this.beanName = name;
    }

    public void outputResult(){
        System.out.println("Bean 的名称为："+ beanName);
        Resource resource = resourceLoader.getResource("classpath:test.txt");
        try {
            System.out.println("ResourceLoader 加载的文件内容为："+ org.apache.commons.io.IOUtils.toString(resource.getInputStream()));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }



}
